﻿using University.Workshop.DataAccess;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using University.Workshop.Model;
using University.Workshop.Business;

namespace University.Workshop.Tests
{
    
    
    /// <summary>
    ///This is a test class for UserWishListDataAccessTest and is intended
    ///to contain all UserWishListDataAccessTest Unit Tests
    ///</summary>
    [TestClass()]
    public class UserWishListDataAccessTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for ViewWishList
        ///</summary>
        [TestMethod()]
        public void ViewWishListTest()
        {
            Random rand = new Random();
            string email = "loqueseauser" + rand.Next(500) + "@gmail.com";
            DateTime birthday = Convert.ToDateTime("04/05/1992");
            UserRegistrationManager.RegisterUser("pedro", "miapellido", 'M',
                                         birthday, email, "pedro123", "pedro123", "Cochabamba",
                                         "Cercado", "7222222", "4401492");
            User user = UserDataAccess.GetUserByEmail(email);
            string email2 = "loqueseauser23@gmail.com";
            DateTime birthday2 = Convert.ToDateTime("04/05/1992");
            UserRegistrationManager.RegisterUser("pedro", "miape", 'M',
                                         birthday2, email2, "loqueseauser2", "loqueseauser2", "Cochabamba",
                                         "Cercado", "7222222", "4401492");
            User user2 = UserDataAccess.GetUserByEmail(email2);
            Product prod = ProductRegistrationManager.RegisterNewProduct("hp 453S 16GB Black", "20", "CELEUDSADSSF FASDFASDFASDFASDFSDFSAF FASDFASFASDFSADFDSF ASFSDAFASDFASFASFASDFADSFASF", "Electronics", false, "Dollars", 1, "1");
            UserWishList actual = new UserWishList();
            UserWishList actual2 = new UserWishList();
            actual2.UserId = user2.Id;
            actual2.ProductId = prod.ProductId;
            actual.UserId = user.Id;
            actual.ProductId = prod.ProductId;
            actual.Status = "Available";
            actual2.Status = "Available";
            actual = UserWishListDataAccess.InsertWishList(actual);
            actual2 = UserWishListDataAccess.InsertWishList(actual2);
            UserWishListDataAccess.ViewWishList(actual);
             
        }

        /// <summary>
        ///A test for InsertWishList
        ///</summary>
        [TestMethod()]
        public void SuccesfulRegistrationTest()
        {

            Random rand = new Random();
            string email = "loqueseauser@gmail.com";
            DateTime birthday = Convert.ToDateTime("04/05/1992");
            UserRegistrationManager.RegisterUser("luis", "miapellido", 'M',
                                         birthday, email, "loqueseauser1", "loqueseauser1", "Cochabamba",
                                         "Cercado", "7222222", "4401492");
            User user = UserDataAccess.GetUserByEmail(email);
            Product prod =  ProductRegistrationManager.RegisterNewProduct(" cellphone Ericcson 16GB", "120", "CELEUDSADSSF FASDFASDFASDFASDFSDFSAF FASDFASFASDFSADFDSF ASFSDAFASDFASFASFASDFADSFASF", "Electronics", false, "Dollars", 1, "1");
            UserWishList actual = new UserWishList();
            actual.UserId = user.Id;
            actual.ProductId = prod.ProductId;
            actual.Status = "Available";
            UserWishList actual2 = new UserWishList();
            string email2 = "loqueseauser2@gmail.com";
            DateTime birthday2 = Convert.ToDateTime("04/05/1992");
            UserRegistrationManager.RegisterUser("ana", "miape", 'M',
                                         birthday2, email2, "loqueseauser2", "loqueseauser2", "Cochabamba",
                                         "Cercado", "7222222", "4401492");
            User user2 = UserDataAccess.GetUserByEmail(email2);
            actual2.UserId = user2.Id;
            actual2.ProductId = prod.ProductId;
            actual2.Status = "Available";
            actual = UserWishListDataAccess.InsertWishList(actual);
            actual2 = UserWishListDataAccess.InsertWishList(actual2);
            Assert.AreNotEqual(null, actual);
            Assert.AreEqual(prod.ProductId, actual.ProductId);
        }

        /// <summary>
        ///A test for GetProductBYUserId
        ///</summary>
        [TestMethod()]
        public void GetProductBYUserIdTest()
        {
            Random rand = new Random();
            string email = "loqueseauserl" + rand.Next(500) + "@gmail.com";
            DateTime birthday = Convert.ToDateTime("04/05/1992");
            UserRegistrationManager.RegisterUser("pedro", "miapellido", 'M',
                                         birthday, email, "pedro123", "pedro123", "Cochabamba",
                                         "Cercado", "7222222", "4401492");
            User user = UserDataAccess.GetUserByEmail(email);
            Product prod = ProductRegistrationManager.RegisterNewProduct("green scarf 2 pieces", "10", "CELEUDSADSSF FASDFASDFASDFASDFSDFSAF FASDFASFASDFSADFDSF ASFSDAFASDFASFASFASDFADSFASF", "Fashion", false, "Dollars", 1, "1");
            UserWishList actual = new UserWishList();
            actual.UserId = user.Id;
            actual.ProductId = prod.ProductId;
            actual.Status = "Available";
            actual = UserWishListDataAccess.InsertWishList(actual);
            UserWishListDataAccess.GetProductBYUserId(actual.UserId);
        }

        /// <summary>
        ///A test for GetUnavailableProducts
        ///</summary>
        [TestMethod()]
        public void GetUnavailableProductsTest()
        {
            Random rand = new Random();
            string email = "jhon_1333413269_per@me.com";
            DateTime birthday = Convert.ToDateTime("04/05/1992");
            UserRegistrationManager.RegisterUser("pedro", "rodriguez", 'M',
                                         birthday, email, "333921555", "333921555", "Cochabamba",
                                         "Cercado", "7222222", "4401492");
            User user = UserDataAccess.GetUserByEmail(email);
            Product prod = ProductRegistrationManager.RegisterNewProduct("portatil 8GB White", "320", "CELEUDSADSSF FASDFASDFASDFASDFSDFSAF FASDFASFASDFSADFDSF ASFSDAFASDFASFASFASDFADSFASF", "Electronics", false, "Dollars", 1, "1");
            UserWishList actual = new UserWishList();
            actual.UserId = user.Id;
            actual.ProductId = prod.ProductId;
            actual.Status = "UnAvailable";
            actual = UserWishListDataAccess.InsertWishList(actual);
            UserWishListDataAccess.GetUnavailableProducts(actual.UserId);
        }

        /// <summary>
        ///A test for UpdateProductStatus
        ///</summary>
        [TestMethod()]
        public void UpdateProductStatusTest()
        {
            Random rand = new Random();
            string email = "loqueseauserb" + rand.Next(500) + "@gmail.com";
            DateTime birthday = Convert.ToDateTime("04/05/1992");
            UserRegistrationManager.RegisterUser("pedro", "apellido", 'M',
                                         birthday, email, "pedro123", "pedro123", "Cochabamba",
                                         "Cercado", "7222222", "4401492");
            User user = UserDataAccess.GetUserByEmail(email);
            Product prod = ProductRegistrationManager.RegisterNewProduct("apple 16GB 2 Pieces", "20", "CELEUDSADSSF FASDFASDFASDFASDFSDFSAF FASDFASFASDFSADFDSF ASFSDAFASDFASFASFASDFADSFASF", "Electronics", false, "Dollars", 1, "1");
            UserWishList actual = new UserWishList();
            actual.UserId = user.Id;
            actual.ProductId = prod.ProductId;
            actual.Status = "Available";
            actual = UserWishListDataAccess.InsertWishList(actual);
            UserWishListDataAccess.UpdateProductStatus(actual.ProductId);
        }

        /// <summary>
        ///A test for GetProductBYProductId
        ///</summary>
        [TestMethod()]
        public void GetProductBYProductIdTest()
        {
            Random rand = new Random();
            string email = "loqueseauserc" + rand.Next(500) + "@gmail.com";
            DateTime birthday = Convert.ToDateTime("04/05/1992");
            UserRegistrationManager.RegisterUser("pedro", "miapellido", 'M',
                                         birthday, email, "pedro123", "pedro123", "Cochabamba",
                                         "Cercado", "7222222", "4401492");
            User user = UserDataAccess.GetUserByEmail(email);
            Product prod = ProductRegistrationManager.RegisterNewProduct(" nintendo 16GB Blue", "20", "CELEUDSADSSF FASDFASDFASDFASDFSDFSAF FASDFASFASDFSADFDSF ASFSDAFASDFASFASFASDFADSFASF", "Electronics", false, "Dollars", 1, "1");
            UserWishList actual = new UserWishList();
            actual.UserId = user.Id;
            actual.ProductId = prod.ProductId;
            actual.Status = "Available";
            actual = UserWishListDataAccess.InsertWishList(actual);
            UserWishListDataAccess.GetProductBYProductId(actual.ProductId);
        }

        /// <summary>
        ///A test for UpdateProductStatusAvailable
        ///</summary>
        [TestMethod()]
        public void UpdateProductStatusAvailableTest()
        {
            Random rand = new Random();
            string email = "loqueseauser" + rand.Next(500) + "@gmail.com";
            DateTime birthday = Convert.ToDateTime("04/05/1992");
            UserRegistrationManager.RegisterUser("firstaName", "lastName", 'M',
                                         birthday, email, "pedro123", "pedro123", "Cochabamba",
                                         "Cercado", "7222222", "4401492");
            User user = UserDataAccess.GetUserByEmail(email);
            Product prod = ProductRegistrationManager.RegisterNewProduct("big motorcicle black", "1220", "CELEUDSADSSF FASDFASDFASDFASDFSDFSAF FASDFASFASDFSADFDSF ASFSDAFASDFASFASFASDFADSFASF", "Motors", false, "Dollars", 1, "1");
            UserWishList actual = new UserWishList();
            actual.UserId = user.Id;
            actual.ProductId = prod.ProductId;
            actual.Status = "Available";
            actual = UserWishListDataAccess.InsertWishList(actual);
            UserWishListDataAccess.UpdateProductStatusAvailable(actual.ProductId);
        }

        /// <summary>
        ///A test for DeleteProductWishList
        ///</summary>
        [TestMethod()]
        public void DeleteProductWishListTest()
        {
            Random rand = new Random();
            string email = "loqueseauserd" + rand.Next(500) + "@gmail.com";
            DateTime birthday = Convert.ToDateTime("04/05/1992");
            UserRegistrationManager.RegisterUser("pedro", "miapellido", 'M',
                                         birthday, email, "pedro123", "pedro123", "Cochabamba",
                                         "Cercado", "7222222", "4401492");
            User user = UserDataAccess.GetUserByEmail(email);
            Product prod = ProductRegistrationManager.RegisterNewProduct("sony cell 16GB Black", "20", "CELEUDSADSSF FASDFASDFASDFASDFSDFSAF FASDFASFASDFSADFDSF ASFSDAFASDFASFASFASDFADSFASF", "Electronics", false, "Dollars", 1, "1");
            UserWishList actual = new UserWishList();
            actual.UserId = user.Id;
            actual.ProductId = prod.ProductId;
            actual.Status = "Available";
            actual = UserWishListDataAccess.InsertWishList(actual);
            UserWishListDataAccess.DeleteProductWishList(actual.ProductId);
        }

        /// <summary>
        ///A test for UserEmail
        ///</summary>
        [TestMethod()]
        public void UserEmailTest()
        {
            Random rand = new Random();
            string email = "loqueseauser" + rand.Next(500) + "@gmail.com";
            DateTime birthday = Convert.ToDateTime("04/05/1992");
            UserRegistrationManager.RegisterUser("firstName", "lastName", 'M',
                                         birthday, email, "pedro123", "pedro123", "Cochabamba",
                                         "Cercado", "7222222", "4401492");
            User user = UserDataAccess.GetUserByEmail(email);
            Product prod = ProductRegistrationManager.RegisterNewProduct("cellphone 16GB Black", "20", "CELEUDSADSSF FASDFASDFASDFASDFSDFSAF FASDFASFASDFSADFDSF ASFSDAFASDFASFASFASDFADSFASF", "Electronics", false, "Dollars",1, "1");
            UserWishList actual = new UserWishList();
            actual.UserId = user.Id;
            actual.ProductId = prod.ProductId;
            actual.Status = "Available";
            actual = UserWishListDataAccess.InsertWishList(actual);
            UserWishListDataAccess.UserEmail(actual.ProductId);
        }

        /// <summary>
        ///A test for WishListProducts
        ///</summary>
        [TestMethod()]
        public void WishListProductsTest()
        {
            Random rand = new Random();
            string email = "loqueseausert"  + "@gmail.com";
            DateTime birthday = Convert.ToDateTime("04/05/1992");
            UserRegistrationManager.RegisterUser("pedro", "miapellido", 'M',
                                         birthday, email, "loqueseauser1", "loqueseauser1", "Cochabamba",
                                         "Cercado", "7222222", "4401492");
            User user = UserDataAccess.GetUserByEmail(email);
            Product prod = ProductRegistrationManager.RegisterNewProduct("new iPhone 16GB Black", "20", "CELEUDSADSSF FASDFASDFASDFASDFSDFSAF FASDFASFASDFSADFDSF ASFSDAFASDFASFASFASDFADSFASF", "Electronics", false, "Dollars",1, "1");
            UserWishList actual = new UserWishList();
            actual.UserId = user.Id;
            actual.ProductId = prod.ProductId;
            actual.Status = "Available";
            actual = UserWishListDataAccess.InsertWishList(actual);
            UserWishListDataAccess.WishListProducts() ;
        }
    }
}
